﻿@{
    Layout = "../Shared/_Default.cshtml";
    ViewBag.PageTitle = T(Res.Name("Title"));
}

<section class="box">
    <script type="text/javascript">
        jQuery(document).ready(function () {
            jQuery.ajax({
                type: 'post',
                url: '@Url.Action(Loc.Act("Formats").Ctrl("ImportExport"))',
                dataType: 'json',
                success: function (rsp) {
                    jQuery('@ID("#ddl_import_format")').empty();
                    jQuery('@ID("#ddl_export_format")').empty();
                    jQuery.each(rsp, function (k, v) {
                        jQuery('@ID("#ddl_import_format")').append('<option value=' + v.id + '>' + v.value + '</option>');
                        jQuery('@ID("#ddl_export_format")').append('<option value=' + v.id + '>' + v.value + '</option>');
                    });
                }
            });
            jQuery('@ID("#dlg_import")').dialog();
            jQuery('@ID("#btn_import")').click(function () {
                jQuery('@ID("#dlg_import")').dialog("open");
            });
            jQuery('@ID("#dlg_export")').dialog();
            jQuery('@ID("#btn_export")').click(function () {
                jQuery('@ID("#dlg_export")').dialog("open");
            });
            jQuery('@ID("#dlg_set")').dialog();
            jQuery('@ID("#btn_set")').click(function () {
                jQuery('@ID("#dlg_set")').dialog("open");
            });
        });
    </script>
    <header>
        <ul class="bar toolbar">
            <li><a id="@ID("btn_set")" class="button" href="#">@T(Res.In("Common").Of("Vocab").Name("Set"))</a></li>
            <li><a id="@ID("btn_import")" class="button" href="#">@T(Res.In("Common").Of("Act").Name("Import"))</a></li>
            <li><a id="@ID("btn_export")" class="button" href="#">@T(Res.In("Common").Of("Act").Name("Export"))</a></li>
        </ul>
        <h3>@ViewBag.PageTitle</h3>
    </header>
    <section>
        @{
            var settings = Model.Items as IEnumerable<dynamic>;
            settings = settings.OrderBy(x => JDM.String(x.Key));
            var groups = settings.Select(x => JDM.String(x.Key).Split(new[]
            {
                '.'
            }, 2)[0]).Distinct();
            foreach(string group in groups)
            {
                <fieldset class="groupbox">
                    <legend>@group</legend>
                    <section>
                        <form action="#">
                            <table>
                            @foreach(var i in settings.Where(x => JDM.String(x.Key).StartsWith(group)))
                            {
                                string hintKey = Res.In("WebAdmin").Of("Help").Of("Config").Name(JDM.String(i.Key).Replace('.', '_'));
                                string hint = T(hintKey);
                                <tr>
                                    <td>
                                        <label>@JDM.String(i.Key)</label>
                                    </td>
                                    <td>
                                        <input type="text" readonly value="@JDM.String(i.Value)" />
                                        @if(hint != hintKey)
                                        {
                                            <span class="hint">@T(Res.In("WebAdmin").Of("Help").Of("Config").Name(JDM.String(i.Key).Replace('.', '_')))</span>
                                        }
                                    </td>
                                </tr>
                            }
                            </table>
                        </form>
                    </section>
                </fieldset>
            }
        }
        <div id="@ID("dlg_export")">
            <form action="@Url.Action(Loc.Act("Export").Ctrl("ImportExport"))" method="post">
                <input type="hidden" name="returnUrl" value="@Request.RawUrl" />
                <input type="hidden" name="name" value="ExportConfigParams" />
                <ul>
                    <li>
                        <select id="@ID("ddl_export_format")" name="formatID"></select>
                    </li>
                </ul>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                </ul>
            </form>
        </div>
        <div id="@ID("dlg_import")">
            <form action="@Url.Action(Loc.Act("Import").Ctrl("ImportExport"))" method="post" enctype="multipart/form-data">
                <input type="hidden" name="returnUrl" value="@Request.RawUrl" />
                <input type="hidden" name="name" value="ImportConfigParams" />
                <ul>
                    <li>
                        <select id="@ID("ddl_import_format")" name="formatID"></select>
                    </li>
                    <li>
                        <input type="file" name="file" />
                    </li>
                </ul>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                </ul>
            </form>
        </div>
        <div id="@ID("dlg_set")">
        @{
            Html.RenderPartial("_Set");
        }
        </div>
    </section>
</section>